/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {boolean}
 */

var findTarget = function (root, k) {
    let res = []
    fn(root)
    let map = new Map()
    // 数组备忘录查找
    for (let i = 0; i < res.length; i++) {
        if (!map.has(k - res[i])) {
            map.set(res[i], i)
        } else {
            return true
        }
    }
    return false
    // 中序遍历
    function fn(root) {
        if (!root) {
            return
        }
        fn(root.left)
        res.push(root.val)
        fn(root.right)
    }
};
